﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.PurchaseFormModelCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.PurchaseFormModelCommandHandler
{
	/// <summary>
	/// 羊只采购修改
	/// </summary>
	public class UpdatePurchaseformmodelHandler : IRequestHandler<UpdatePurchaseformmodelCommand, Results<int>>
	{

		private readonly IPurchaseFormModelService _purchaseFormModelService;
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="purchaseFormModelService"></param>
		public UpdatePurchaseformmodelHandler(IPurchaseFormModelService purchaseFormModelService)
		{
			_purchaseFormModelService = purchaseFormModelService;
		}
		/// <summary>
		/// 羊只档案修改
		/// </summary>
		/// <param name="request"></param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		public async Task<Results<int>> Handle(UpdatePurchaseformmodelCommand request, CancellationToken cancellationToken)
		{
			var entity = new Purchaseformmodel()
			{
				AdjustTheAmount = request.AdjustTheAmount,
				Amount = request.Amount,
				AverageUnitOnly = request.AverageUnitOnly,
				SettlementAmount = request.SettlementAmount,
				BuildingId = request.BuildingId,
				InboundQuantity = request.InboundQuantity,
				BuildingName = request.BuildingName,
				Buyer = request.Buyer,
				ColumnId = request.ColumnId,
				ColumnName = request.ColumnName,
				CreateBy = request.CreateBy,
				CreateTime = request.CreateTime,
				DateOfPurchase = request.DateOfPurchase,
				Document = request.Document,
				EarTag = request.EarTag,
				Gender = request.Gender,
				GoodName = request.GoodName,
				IsDel = request.IsDel,
				LabelPackage = request.LabelPackage,
				PurchaseFormDesc = request.PurchaseFormDesc,
				PurchaseFormId = request.PurchaseFormId,
				SerialNumber = request.SerialNumber,
				SheepType = request.SheepType,
				SummaryEnum = request.SummaryEnum,
				TotalWeight = request.TotalWeight,
				UnitDiscounts = request.UnitDiscounts,
				UnitOfMeasure = request.UnitOfMeasure,
				UpdateBy = request.UpdateBy,
				UpdateTime = request.UpdateTime,
				Variety = request.Variety,
				VendorSnowId = request.VendorSnowId,
				Warehouse = request.Warehouse,
			};
			var entitys=await _purchaseFormModelService.UpdatePurchaseformmodel(entity);
			return Results<int>.DataResult(entitys);
		}
	}
}
